package com.qfhd.soft.cjzcore.TaskCenter.GDT;

import android.app.Activity;
import android.widget.FrameLayout;

import com.qfhd.soft.cjzcore.Core.CJLogger;
import com.qfhd.soft.cjzcore.Listener.CJLoadFinishListener;
import com.qq.e.ads.splash.SplashAD;
import com.qq.e.ads.splash.SplashADListener;
import com.qq.e.comm.util.AdError;

public class CJGTD_Splash implements SplashADListener {

    private SplashAD splashAD;
    private Activity mActivity;
    private CJLoadFinishListener overListener;

    private static CJGTD_Splash cjgtd_splash;

    public static CJGTD_Splash getInstance() {
        if (cjgtd_splash == null) {
            synchronized (CJGDTsdk.class) {
                cjgtd_splash = new CJGTD_Splash();
            }
        }
        return cjgtd_splash;
    }

    public void begin(Activity activity, FrameLayout adContainer, CJLoadFinishListener overListener) {
        mActivity = activity;
        this.overListener = overListener;
        splashAD = new SplashAD(activity, CJGDTsdk.APPID, CJGDTsdk.SplashId, this, 0);
        splashAD.fetchAndShowIn(adContainer);
    }

    @Override
    public void onADDismissed() {
        CJLogger.v("GTD Splash onADDismissed");
        if (overListener != null) {
            overListener.loadFinish(null);
        }
    }

    @Override
    public void onNoAD(AdError adError) {
        CJLogger.v("GTD Splash failed:" + adError.toString());
        if (overListener != null) {
            overListener.loadFinish(null);
        }
    }

    @Override
    public void onADPresent() {

    }

    @Override
    public void onADClicked() {
        CJLogger.v("GDT Splash onADClicked");
    }

    @Override
    public void onADTick(long l) {
        //毫秒
        if(l < 1*1000){
            if (overListener != null) {
                overListener.loadFinish(null);
            }
        }
    }

    @Override
    public void onADExposure() {

    }

    @Override
    public void onADLoaded(long l) {
        //告加载成功的回调，在fetchAdOnly的情况下，表示广告拉取成功可以显示了。
        // 广告需要在SystemClock.elapsedRealtime <expireTimestamp前展示，否则在showAd时会返回广告超时错误。
        CJLogger.v("GDT Splash onADLoaded");
    }
}
